package com.farvision.common.utils;

import com.farvision.common.config.LogoConfig;
import com.farvision.common.enums.EmailTypeEnum;
import com.farvision.common.service.impl.MailServiceImpl;


public class MailUtils implements Runnable {
    private String email;// 收件人邮箱
    

    private static final String logo=SpringBeanUtil.getBean(LogoConfig.class).getPath();

    private static String host;

    private String content;// 内容
    
    private String type;
    
    MailServiceImpl mailService =SpringBeanUtil.getBean(MailServiceImpl.class);
    LogoConfig logoConfig=SpringBeanUtil.getBean(LogoConfig.class);

    public MailUtils(String email, String content) {
        this.email = email;
        this.content = content;
    }

    public MailUtils(String email, String content, String type) {
        this.email = email;
        this.content = content;
        this.type=type;
    }

    public void run() {
       try {
           if(EmailTypeEnum.ACTIVATION_CODE.getType().equals(this.type)){
               sendActivationcode1();
           }else if(EmailTypeEnum.SCHEDULE.getType().equals(this.type)){
               sendConsult(this.content);
           }else if(EmailTypeEnum.VERIFICATION_CODE.getType().equals(this.type)) {
               sendVerificationCode();
           }else if(EmailTypeEnum.BUG_NOTIFICATION.getType().equals(this.type)) {
               sendBUGNotification();
           }
           
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private String logoHtml(){
        if(logoConfig.getShow()==true) {
            return  "<img src=\" "+logo +"\" alt=\"logo\">";
        } else{
            return "";
        }
    }

    private String phoneHtml(){
        if(logoConfig.getShow()==true) {
            return    "            <div style=\"display: flex;justify-content: space-between;\">\n" +
                    "              <span class=\"footer-info\">联系电话：400-888-6846（9:00-18:00）</span>\n" +
                    "              <span class=\"footer-info\">联系邮箱：info@anban.tech</span>\n" +
                    "            </div>\n" ;
        } else{
            return "";
        }
    }

    private String urlHtml(){
        if(logoConfig.getShow()==true) {
            return       "        <p class=\"center-text footer-info\">【安般易恒】网站：https://www.fuzzing.tech</p>\n" ;
        } else{
            return "";
        }
    }

    private String yihengHtml(){
        if(logoConfig.getShow()==true) {
            return       "安般易恒" ;
        } else{
            return "模糊测试系统";
        }
    }
    
    private void sendBUGNotification() {
        String content="<!DOCTYPE html>\n" +
                "<html lang=\"en\">\n" +
                "  <head>\n" +
                "    <meta charset=\"UTF-8\" />\n" +
                "    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n" +
                "    <title>bug通知</title>\n" +
                "    <style>\n" +
                "      .center-box {\n" +
                "        margin: auto;\n" +
                "        width: 640px;\n" +
                "        border: 1px;\n" +
                "      }\n" +
                "      .box{\n" +
                "        background: #FFFFFF;\n" +
                "        box-shadow: 0px 2px 4px 3px rgba(0, 0, 0, 0.03);\n" +
                "        padding: 22px 50px;\n" +
                "      }\n" +
                "      .center-text {\n" +
                "        margin: auto;\n" +
                "        text-align: center;\n" +
                "      }\n" +
                "      .logo {\n" +
                "        margin: 48px auto 51px;\n" +
                "      }\n" +
                "      .info{\n" +
                "        font-family: PingFang SC;\n" +
                "        font-style: normal;\n" +
                "        font-weight: 500;\n" +
                "        font-size: 18px;\n" +
                "        line-height: 25px;\n" +
                "        letter-spacing: 0.09px;\n" +
                "        color: #303133;\n" +
                "      }\n" +
                "      .footer-info{\n" +
                "        font-family: PingFang SC;\n" +
                "        font-style: normal;\n" +
                "        font-weight: 500;\n" +
                "        font-size: 14px;\n" +
                "        line-height: 20px;\n" +
                "        color: #303133;\n" +
                "        mix-blend-mode: normal;\n" +
                "        opacity: 0.3;\n" +
                "      }\n" +
                "      .line{\n" +
                "        margin: 76px 0 21px;\n" +
                "      }\n" +
                "      .message-box{\n" +
                "        background: #F5F6FA;\n" +
                "        border: 1px solid #C4C6CF;\n" +
                "        box-sizing: border-box;\n" +
                "        border-radius: 10px;\n" +
                "        margin-top: 42px;\n" +
                "      }\n" +
                "      .message-item{\n" +
                "        margin: 32px 46px;\n" +
                "        font-weight: 500;\n" +
                "        font-size: 22px;\n" +
                "        line-height: 31px;\n" +
                "        color: #303133;\n" +
                "        vertical-align: middle;\n" +
                "      }\n" +
                "      .message-item-title{\n" +
                "        font-family: PingFang SC;\n" +
                "        font-style: normal;\n" +
                "        font-weight: normal;\n" +
                "        font-size: 18px;\n" +
                "        line-height: 25px;\n" +
                "        color: #6B748F;\n" +
                "      }\n" +
                "      .message-item-info{\n" +
                "        margin-left: 8px;\n" +
                "        word-wrap:break-word; \n" +
                "        word-break:break-all; \n" +
                "        display:inline-block;\n" +
                "        vertical-align:middle\n" +
                "      }\n" +
                "    </style>\n" +
                "  </head>\n" +
                "  <body>\n" +
                "    <div class=\"center-box\" style=\"margin-top: 50px;\">\n" +
                "      <div class=\"box\">\n" +
                "        <div class=\"center-text logo\">\n" +

                    logoHtml()+
           

                "         \n" +
                "        </div>\n" +
                "        <div>\n" +
                "          <h2 class=\"info\">您好！</h2>\n" +
                "          <h3 class=\"info\">\n" +
                "            您的项目"+this.content+"请及时处理！\n" +
                "          </h3>\n" +
                "          <h3 class=\"info\">\n" +
                "          </h3>\n" +
                "          <div>\n" +
                "            <div class=\"line\">\n" +
                "              <svg width=\"543\" height=\"1\" viewBox=\"0 0 543 1\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n" +
                "                <path d=\"M0.5 0.5H542.5\" stroke=\"#C4C6CF\" stroke-width=\"0.5\" stroke-linecap=\"square\"/>\n" +
                "              </svg>\n" +
                "            </div>\n" +

                phoneHtml()+

                "          </div>\n" +
                "        </div>\n" +
                "      </div>\n" +
                "      <div class=\"center-box\" style=\"margin-top: 22px;margin-bottom:50px\">\n" +

                urlHtml()+

                "      </div>\n" +
                "    </div>\n" +
                "  </body>\n" +
                "</html>\n";
        mailService.sendHtmlMail(email,"远届aps订单排产完成通知",content);
    }

    private void sendVerificationCode() {
        String content="<!DOCTYPE html>\n" +
                "<html lang=\"en\">\n" +
                "  <head>\n" +
                "    <meta charset=\"UTF-8\" />\n" +
                "    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n" +
                "    <title>验证码</title>\n" +
                "    <style>\n" +
                "      .center-box {\n" +
                "        margin: auto;\n" +
                "        width: 640px;\n" +
                "        border: 1px;\n" +
                "      }\n" +
                "      .box{\n" +
                "        background: #FFFFFF;\n" +
                "        box-shadow: 0px 2px 4px 3px rgba(0, 0, 0, 0.03);\n" +
                "        padding: 22px 50px;\n" +
                "      }\n" +
                "      .center-text {\n" +
                "        margin: auto;\n" +
                "        text-align: center;\n" +
                "      }\n" +
                "      .logo {\n" +
                "        margin: 48px auto 51px;\n" +
                "      }\n" +
                "      .info{\n" +
                "        font-family: PingFang SC;\n" +
                "        font-style: normal;\n" +
                "        font-weight: 500;\n" +
                "        font-size: 18px;\n" +
                "        line-height: 25px;\n" +
                "        letter-spacing: 0.09px;\n" +
                "        color: #303133;\n" +
                "      }\n" +
                "      .footer-info{\n" +
                "        font-family: PingFang SC;\n" +
                "        font-style: normal;\n" +
                "        font-weight: 500;\n" +
                "        font-size: 14px;\n" +
                "        line-height: 20px;\n" +
                "        color: #303133;\n" +
                "        mix-blend-mode: normal;\n" +
                "        opacity: 0.3;\n" +
                "      }\n" +
                "      .line{\n" +
                "        margin: 76px 0 21px;\n" +
                "      }\n" +
                "      .message-box{\n" +
                "        background: #F5F6FA;\n" +
                "        border: 1px solid #C4C6CF;\n" +
                "        box-sizing: border-box;\n" +
                "        border-radius: 10px;\n" +
                "        margin-top: 42px;\n" +
                "      }\n" +
                "      .message-item{\n" +
                "        margin: 32px 46px;\n" +
                "        font-weight: 500;\n" +
                "        font-size: 22px;\n" +
                "        line-height: 31px;\n" +
                "        color: #303133;\n" +
                "        vertical-align: middle;\n" +
                "      }\n" +
                "      .message-item-title{\n" +
                "        font-family: PingFang SC;\n" +
                "        font-style: normal;\n" +
                "        font-weight: normal;\n" +
                "        font-size: 18px;\n" +
                "        line-height: 25px;\n" +
                "        color: #6B748F;\n" +
                "      }\n" +
                "      .message-item-info{\n" +
                "        margin-left: 8px;\n" +
                "        word-wrap:break-word; \n" +
                "        word-break:break-all; \n" +
                "        display:inline-block;\n" +
                "        vertical-align:middle\n" +
                "      }\n" +
                "    </style>\n" +
                "  </head>\n" +
                "  <body>\n" +
                "    <div class=\"center-box\" style=\"margin-top: 50px;\">\n" +
                "      <div class=\"box\">\n" +
                "        <div class=\"center-text logo\">\n" +

                logoHtml()+

                "        </div>\n" +
                "        <div>\n" +
                "          <h2 class=\"info\">您好！</h2>\n" +
                "          <h3 class=\"info\">\n" +

                yihengHtml()+
                "·【验证码】通知，以下是您的验证码，请妥善保管，泄漏有风险，请勿转发给其他人。\n" +

                "          </h3>\n" +
                "          <div class=\"message-box\">\n" +
                "            <p class=\"message-item\">\n" +
                "              <span class=\"message-item-info\" style=\"width:350px;\">"+this.content+"</span>\n" +
                "            </p>\n" +
                "          </div>\n" +
                "          <div>\n" +
                "            <div class=\"line\">\n" +
                "              <svg width=\"543\" height=\"1\" viewBox=\"0 0 543 1\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n" +
                "                <path d=\"M0.5 0.5H542.5\" stroke=\"#C4C6CF\" stroke-width=\"0.5\" stroke-linecap=\"square\"/>\n" +
                "              </svg>\n" +
                "            </div>\n" +

                phoneHtml()+

                "          </div>\n" +
                "        </div>\n" +
                "      </div>\n" +
                "      <div class=\"center-box\" style=\"margin-top: 22px;margin-bottom:50px\">\n" +

                urlHtml()+

                "      </div>\n" +
                "    </div>\n" +
                "  </body>\n" +
                "</html>\n";
        mailService.sendHtmlMail(email,"F远届aps平台验证码",content);
        
    }

    private void sendActivationcode(){

        mailService.sendHtmlMail(email,"F远届aps平台账号激活链接","<html><head></head><body><h1>" +
                // "这是易恒模糊测试平台的激活邮件,激活请点击以下链接</h1><h3>" +
                "这是易恒模糊测试平台的激活邮件,激活码为：</h1><h3>" +
                // "<a href='http://43.248.189.190:8081/fuzzingback/user/changeStatus?ccode="+this.content+"'>点击此链接激活账户</a>" +
                this.content+
                "</h3></body></html>");
    }

    private void sendActivationcode1(){

        String content="<!DOCTYPE html>\n" +
                "<html lang=\"en\">\n" +
                "  <head>\n" +
                "    <meta charset=\"UTF-8\" />\n" +
                "    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n" +
                "    <title>验证码</title>\n" +
                "    <style>\n" +
                "      .center-box {\n" +
                "        margin: auto;\n" +
                "        width: 640px;\n" +
                "        border: 1px;\n" +
                "      }\n" +
                "      .box{\n" +
                "        background: #FFFFFF;\n" +
                "        box-shadow: 0px 2px 4px 3px rgba(0, 0, 0, 0.03);\n" +
                "        padding: 22px 50px;\n" +
                "      }\n" +
                "      .center-text {\n" +
                "        margin: auto;\n" +
                "        text-align: center;\n" +
                "      }\n" +
                "      .logo {\n" +
                "        margin: 48px auto 51px;\n" +
                "      }\n" +
                "      .info{\n" +
                "        font-family: PingFang SC;\n" +
                "        font-style: normal;\n" +
                "        font-weight: 500;\n" +
                "        font-size: 18px;\n" +
                "        line-height: 25px;\n" +
                "        letter-spacing: 0.09px;\n" +
                "        color: #303133;\n" +
                "      }\n" +
                "      .footer-info{\n" +
                "        font-family: PingFang SC;\n" +
                "        font-style: normal;\n" +
                "        font-weight: 500;\n" +
                "        font-size: 14px;\n" +
                "        line-height: 20px;\n" +
                "        color: #303133;\n" +
                "        mix-blend-mode: normal;\n" +
                "        opacity: 0.3;\n" +
                "      }\n" +
                "      .line{\n" +
                "        margin: 76px 0 21px;\n" +
                "      }\n" +
                "      .message-box{\n" +
                "        background: #F5F6FA;\n" +
                "        border: 1px solid #C4C6CF;\n" +
                "        box-sizing: border-box;\n" +
                "        border-radius: 10px;\n" +
                "        margin-top: 42px;\n" +
                "      }\n" +
                "      .message-item{\n" +
                "        margin: 32px 46px;\n" +
                "        font-weight: 500;\n" +
                "        font-size: 22px;\n" +
                "        line-height: 31px;\n" +
                "        color: #303133;\n" +
                "        vertical-align: middle;\n" +
                "      }\n" +
                "      .message-item-title{\n" +
                "        font-family: PingFang SC;\n" +
                "        font-style: normal;\n" +
                "        font-weight: normal;\n" +
                "        font-size: 18px;\n" +
                "        line-height: 25px;\n" +
                "        color: #6B748F;\n" +
                "      }\n" +
                "      .message-item-info{\n" +
                "        margin-left: 8px;\n" +
                "        word-wrap:break-word; \n" +
                "        word-break:break-all; \n" +
                "        display:inline-block;\n" +
                "        vertical-align:middle\n" +
                "      }\n" +
                "    </style>\n" +
                "  </head>\n" +
                "  <body>\n" +
                "    <div class=\"center-box\" style=\"margin-top: 50px;\">\n" +
                "      <div class=\"box\">\n" +
                "        <div class=\"center-text logo\">\n" +

                logoHtml()+

                "        </div>\n" +
                "        <div>\n" +
                "          <h2 class=\"info\">您好！</h2>\n" +
                "          <h3 class=\"info\">\n" +

                yihengHtml()+
                "·【激活码】通知，以下是您的激活码，请妥善保管，泄漏有风险，请勿转发给其他人。\n" +

                "          </h3>\n" +
                "          <div class=\"message-box\">\n" +
                "            <p class=\"message-item\">\n" +
                "              <span class=\"message-item-info\" style=\"width:350px;\">"+this.content+"</span>\n" +
                "            </p>\n" +
                "          </div>\n" +
                "          <div>\n" +
                "            <div class=\"line\">\n" +
                "              <svg width=\"543\" height=\"1\" viewBox=\"0 0 543 1\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n" +
                "                <path d=\"M0.5 0.5H542.5\" stroke=\"#C4C6CF\" stroke-width=\"0.5\" stroke-linecap=\"square\"/>\n" +
                "              </svg>\n" +
                "            </div>\n" +

                phoneHtml()+

                "          </div>\n" +
                "        </div>\n" +
                "      </div>\n" +
                "      <div class=\"center-box\" style=\"margin-top: 22px;margin-bottom:50px\">\n" +

                urlHtml() +

                "      </div>\n" +
                "    </div>\n" +
                "  </body>\n" +
                "</html>\n";
        mailService.sendHtmlMail(email,"F远届aps平台账号激活码",content);
        
    }

    private void sendConsult(String content){
        mailService.sendHtmlMail(email,"F远届aps平台客户咨询通知",this.content);
    }
}
